-
Notifications
You must be signed in to change notification settings - Fork 26
Support dynamic selection of DMA channels on STM32 #500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Tested on STM32L475-IOT01A, STM32H563VI(custom), STM32H750VB(custom) boards.
|
OK code looks good, just want to do a test run with the CI test shield. Will do that on my end soon. One thing I should mention though, we really should create a doc page about how to use the stm_dma_utils code, both from within Mbed and from user code. I think it's a way easier way to use DMA on STM32, but it can be a little hard to figure out if you haven't seen it before, and you have to use it when working with Mbed as it takes over all the DMA interrupts. |
|
Hmm, running your branch on NUCLEO_U083RC I get Looks like at the time that you are creating the mutex, the RTX memory pools have not been initialized yet so allocation is failing. I think we need to either move the mutex creation later in the init process, or provide a memory block so that it doesn't need to allocate. |
It's a bit strange; normal programs don't encounter this error (RTOS enabled), but the GreenTea test program does report the error. I changed stm_init_dma_mutex to use static memory for dmaMutex's control block and run the GreenTea tests on B-U585I-IOT02A. It seems OK, please test again. Thanks. |
|
OK, I was able to run your branch and it passed all DMA SPI basic tests on NUCLEO_H563ZI! |
Summary of changes
On newer STM32 devices, the DMA channels may be chosen arbitrarily.
This PR allows the use of macros MBED_ANY_GPDMA_MODULE and MBED_ANY_DMA_CHANNEL in DMALinkInfo declarations, so that we can dynamically select unused DMA channels at runtime on the supported STM32 devices.
Impact of changes
The definition of the DMAHandlePointer type has been changed. DMAHandlePointer is now a struct that, in addition to containing a DMA handle pointer, also includes the DMA instance and channel index.
The stm_free_dma_link function now accpets a pointer to DMAHandlePointer.
The spi_s/qspi_s/ospi_s structs now contain dmaHandle members of the DMAHandlePointer type, instead of dmaInitialized members.
A new function is implemented to find an unused DMA channel:
When the RTOS is present, a mutex object is used for synchronization between threads. New functions stm_init_dma_mutex/stm_lock_dma_mutex/stm_unlock_dma_mutex are introduced to manage the mutex ojbect. stm_init_dma_mutex is called in the mbed_sdk_init function. stm_lock_dma_mutex/stm_unlock_dma_mutex are called in stm_init_dma_link/stm_free_dma_link functions.
Migration actions required
Documentation
None.
Pull request type
Test results
I have tested the QSPI DMA on three boards:
STM32L475E-IOT01A: this board does not have a DMAMUX, so fixed DMA instance and channel indexes are used.
custom STM32H750VB board: the DMA instance is fixed(MDMA), but the DMA channel is dynamically selected.
custom STM32H563VI board: both DMA instance and channel are dynamically selected.
I'll test more boards later.